package com.pureut.storage.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.storage.dto.PickingSchemeDto;
import com.pureut.storage.service.PickingSchemeService;
import com.pureut.storage.vo.PickingSchemeRelationVo;
import com.pureut.storage.vo.PickingSchemeVo;
import com.pureut.storage.vo.SchemeVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 拣货方案控制层
 * Author:C
 * Date:2022/12/21 15:46
 * @DESC
 */
@RestController
@RequestMapping("/picking-scheme")
public class PickingSchemeController extends BaseController {

    @Resource
    PickingSchemeService pickingSchemeService;

    /**
     * 获取拣货方案列表
     */
    @RequiresPermissions("warehouse:warmanage:picking:list")
    @GetMapping("/list")
    public TableDataInfo getList(PickingSchemeVo pickingSchemeVo) {
        startPage();
        //查询拣货方案列表
        List<PickingSchemeDto> list = pickingSchemeService.getList(pickingSchemeVo);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @RequiresPermissions("warehouse:warmanage:picking:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody PickingSchemeVo pickingSchemeVo) {
        return toAjax(pickingSchemeService.addPickingScheme(pickingSchemeVo));
    }

    /**
     * 修改
     */
    @RequiresPermissions("warehouse:warmanage:picking:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody PickingSchemeVo pickingSchemeVo) {
        return toAjax(pickingSchemeService.updatePickingScheme(pickingSchemeVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("warehouse:warmanage:picking:query")
    @GetMapping("/view/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(pickingSchemeService.getView(id));
    }

    /**
     * 关联
     */
    @RequiresPermissions("warehouse:warmanage:picking:relation")
    @Log(title = "关联", businessType = BusinessType.INSERT)
    @PostMapping("/relation")
    public AjaxResult relation(@Validated @RequestBody PickingSchemeRelationVo pickingSchemeRelationVo) {
        return toAjax(pickingSchemeService.relation(pickingSchemeRelationVo));
    }

    /**
     * 解绑
     */
    @RequiresPermissions("warehouse:warmanage:picking:relieve")
    @Log(title = "解绑", businessType = BusinessType.UPDATE)
    @GetMapping("/relieve/{id}")
    public AjaxResult relieve(@PathVariable("id") Long id) {
        return toAjax(pickingSchemeService.relieve(id));
    }

    /**
     * 删除
     */
    @RequiresPermissions("warehouse:warmanage:picking:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable("ids") String ids) {
        return toAjax(pickingSchemeService.deletePickingScheme(ids));
    }

    /**
     * 根据物料编码、关联信息、默认标志获取仓库-库区-库位-批次号信息
     */
    @PostMapping("/getSchemeData")
    public AjaxResult getSchemeData(@RequestBody SchemeVo schemeVo) {
        return AjaxResult.success(pickingSchemeService.getSchemeData(schemeVo));
    }
}

